<?php
	class Email extends CI_Controller{

		function __construct(){
			parent::__construct();
			$this->load->library('phpmailer');
		}

		public function index(){
			
		}
		/**
		 * [sendmail description]
		 * @param  string $arraymail [description]
		 *         string $arraymail['subject'] [description]
		 *         string $arraymail['to'] [description]
		 *         string $arraymail['body'] [description]         
		 * @return [type]            [description]
		 */
		public function send_mail($array_mail = array(), $path_attach = '')
		{

			if(!empty($array_mail))
			{	
				$mail = new PHPMailer();
			    $mail->IsSMTP();
				$mail->Port=PORT;
				$mail->CharSet= 'UTF-8';
				$mail->SMTPSecure = SMTPSECURE; // OR SSL
				$mail->Host=HOST_MAIL;
				$mail->SMTPAuth=true;
				$mail->Username=USERNAME_EMAIL;
				$mail->Password=PASSWORD_EMAIL;
				$mail->From=ADMIN_MAIL;
				$mail->FromName='No reply';
				$mail->Sender=ADMIN_MAIL;
				$mail->Subject=$array_mail['SUBJECT'];
				$mail->AddAddress($array_mail['TO']);
				$mail->Body = $array_mail['BODY'];
				$mail->IsHTML(true);

				if( $path_attach ){

					$mail->AddAttachment($path_attach);
				}

				$mail->SMTPDebug = 2; 

				$mail->AltBody="Admin";
				if ($mail->Send())
				{
					return true;
				}
				else
				{
					return false;
				}	
			}
			else
			{
				return false;
			}
		}
	}
?>